package com.sdut.material.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdut.material.mapper.FactorMapper;
import com.sdut.material.pojo.Factor;
import com.sdut.material.pojo.Material;
import com.sdut.material.pojo.vo.DemandVO;
import com.sdut.material.pojo.vo.LayUISelectMVO;
import com.sdut.material.service.IFactorService;
import com.sdut.material.service.IMaterialService;
import com.sdut.material.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Yu
 * @since 2022-04-20
 */
@Service
public class FactorServiceImpl extends ServiceImpl<FactorMapper, Factor> implements IFactorService {
    @Autowired
    private IMaterialService materialService;
    @Autowired
    private FactorMapper factorMapper;
    @Override
    public JSONResult selectAllFactors(DemandVO demandVO) {
        int materialId = demandVO.getMaterialId();
        int demandCount = demandVO.getDemandCount();
        Map<String,Object> map = new HashMap<>();
        Material material = materialService.selectById(materialId);
        map.put("material",material);
        map.put("demandCount",demandCount);
        List<Factor> factors = factorMapper.selectList(new QueryWrapper<>());
        List<LayUISelectMVO> list = new ArrayList<>();
        for (Factor factor : factors) {
            LayUISelectMVO layUISelectMVO = new LayUISelectMVO();
            layUISelectMVO.setId(factor.getId());
            layUISelectMVO.setName(factor.getName());
            layUISelectMVO.setStatus(1);
            list.add(layUISelectMVO);
        }
        map.put("allFactors",list);
        return JSONResult.ok(map);
    }
}
